<template>
	<view>
		<view clsss="my-block">
		  <view class="my__bg">
		    <image src="/static/logo.png" />
		  </view>
		</view>
		<view>
		  <u-cell-group>
			<u-cell title="当前版本" :value="currentVersion"></u-cell>
			<u-cell isLink :value="currentVersion == newVersion?'':newText" @click="updateVersion">
			    <view slot="title" class="u-slot-title">
					<text class="u-cell-text">升级最新版本</text>
					<image v-if="currentVersion != newVersion" src="https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/526dbc5d0e8b40e79f97c8b95f4b0503.png"
					       style="margin: 0 0 -15rpx 20rpx;width: 50rpx;height: 50rpx;">
				</view>
			</u-cell>
		  </u-cell-group>
		</view>
	</view>
</template>

<script>
	import { getConfigKey } from '@/api/config.js'
	import check from '@/utils/checkupdate'
	export default {
		data() {
			return {
				currentVersion:'',
				newVersion:'',
				newText:'',
			}
		},
		onLoad() {
			this.getNewVersion()
		},
		methods: {
			async getConfigKeyData(configKey){
				const { data } = await getConfigKey(configKey)
				if(data.code == 200){
					this.newText = '最新'+ data.data.configValue
					this.newVersion = data.data.configValue
				}
			},
			updateVersion(){
				if(this.currentVersion == this.newVersion){
					uni.showToast({
						title: '当前已经是最新版本',
						icon: 'none'
					})
					return
				}
				// #ifdef APP-PLUS
				check.check()
				// #endif
			},
			getNewVersion(){
				let that = this
				// #ifdef APP-PLUS
				plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
					that.currentVersion = widgetInfo.version
					let platform = plus.os.name.toLocaleLowerCase()
					that.getConfigKeyData(platform)
				})
				// #endif
			},
		}
	}
</script>

<style lang="scss" scoped>
.my-block {
  background-color: #1b2b8d;
  border-radius: 20rpx;
}

.my__bg {
  height: 300rpx;
  display: flex;
  flex-direction: column;
  color: white;
  // justify-content: center;
  align-items: center;
  background-size: cover;

  image {
    height: 180rpx;
    width: 160rpx;
    margin-top: 54rpx;
    // margin-bottom: 20rpx;
  }
}
</style>
